package com.boang.list;

import java.util.ArrayList;
import java.util.Iterator;

/*
  @author: 13813
  @date: 2024/11/28 14:09
*/
public class ArrayListDemo {
    public static void main(String[] args) {
        ArrayList arrayList = new ArrayList();

        //增
        arrayList.add("b");
        arrayList.add("a");
        arrayList.add("c");

        //改
//        arrayList.set(1, "A");

        //查
//        System.out.println(arrayList.get(1));

        //删
//        arrayList.remove(1);

//        System.out.println(arrayList.toString());


        //遍历
       /* for (int i = 0; i < arrayList.size(); i++) {
            System.out.println(arrayList.get(i));
        }*/

        /*for (Object s : arrayList) {
            System.out.println(s);
        }*/

        Iterator iterator = arrayList.iterator();

//        iterator.hasNext()//有没有下一个数据，有 true, 没有 false
        while (iterator.hasNext()){
            Object next = iterator.next();//取一个数据
            System.out.println(next);
        }
    }
}
